var path = require('path')
var webpack = require('webpack');
//把css文件单独打包的插件,演示分离使用
var ExtractTextPlugin = require("extract-text-webpack-plugin");
//复制文件到指定位置
var CopyWebpackPlugin = require('copy-webpack-plugin');
//抽离css,将css文件抽离,输出到与webpack.config.js同一目录下面的assets文件夹下
var extractCSS = new ExtractTextPlugin('assets/[name]-one.css');
//抽离less
var extractLESS = new ExtractTextPlugin('assets/[name]-two.css');
module.exports = {
    entry: {
        //js入口文件,如果是多页面应用,可以指定多个入口js
        app: "./app.js",
        //css入口文件,做样式分离,此js文件用来导入css或者less,然后通过extractTextPlugin抽出
        adminlteSkin: path.resolve(__dirname, "skin/default.js")//样式文件,通过js转换
    },
    output: {
        path: path.resolve(__dirname),
        //js文件输出目录
        filename: "assets/[name].js"
    }
    ,
    module: {
        loaders: [
            {
                test: /\.(eot|svg|ttf|woff|woff2)(\?\S*)?$/,
                loader: 'file-loader',//loader这里还可以配置路径,指定字体文件生成的地方
                query: {
                    //字体文件输出目录
                    name: "assets/[name].[ext]",
                    //改变css文件的路径引用问题,解决原来字体引用路径assets/assets的问题
                    publicPath: "/"
                }
            },
            {
                test: /\.(png|jpe?g|gif|svg)(\?\S*)?$/,
                loader: 'file-loader',
                query: {
                    name: "assets/img/[name].[ext]",
                    publicPath: "/"
                }
            },
            {
                //编译adminlteSkin.js引入的css
                test: /\.css$/,
                use: extractCSS.extract({
                    use: ['css-loader', 'postcss-loader']
                })
            },
            {
                //编译adminlteSkin.js引入的less
                test: /\.less$/,
                use: extractLESS.extract({
                    use: ['css-loader', 'less-loader']
                })
            }
        ]
    },
    //别忘了引入插件
    plugins: [
        extractCSS,
        extractLESS,
        new CopyWebpackPlugin([
            {
                //将assets复制到public目录下
                from: "assets", to: "../../public/assets"
            }
        ])
    ]
}